package com.ruoyi.boc.service.impl;

import com.ruoyi.boc.service.IBocLdapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.stereotype.Service;

import static org.springframework.ldap.query.LdapQueryBuilder.query;

@Service
public class BocLdapServiceImpl implements IBocLdapService {
    @Autowired
    private LdapTemplate ldapTemplate;

    private static String filter= "(&(&(objectclass=organizationalPerson)(objectclass=person)(objectclass=top))(sAMAccountName=%s))";

    @Override
    public boolean authenticate(String employeeNo, String password) {
        ldapTemplate.setIgnorePartialResultException(true);
        String filterStr = String.format(filter, employeeNo);
        return ldapTemplate.authenticate("", filterStr, password);
    }
}
